package com.cy.pj.goods.dao;

import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 自定义GoodsDao接口实现类,在此实现类中基于SqlSession对象
 */
@Repository
public class GoodsDaoImpl implements GoodsDao{

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public List<Goods> findGoods() {
        System.out.println("----");
        //1,获取sqlSession对象
        SqlSession session = sqlSessionFactory.openSession();
        //2,基于sqlSession实现商品查询
        String Statement = "com.cy.pj.goods.dao.GoodsDao.findGoods";//nameSpace+elementId
        List<Goods> list = session.selectList(Statement);
        //3,释放资源
        session.close();
        //4,返回结果
        return list;
    }
}
